package com.jp.knowledge.activity;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;

import com.google.gson.JsonObject;
import com.jp.knowledge.R;
import com.jp.knowledge.http.HttpHelper;

/**
 * Created by 528787067@qq.com on 2017/7/28.
 */

public class AdjustSortImageActivity extends AdjustSortActivity {

	private int action;
	private String tagId;

	@Override
	protected void init() {
		super.init();
		action = getIntent().getIntExtra("action", 1);
		collectionView.setVisibility(View.GONE);
		collectionBtn.setVisibility(View.GONE);
		itemChoice.setVisibility(View.GONE);
		itemTime.setVisibility(View.GONE);
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if(resultCode == RESULT_OK && data != null && requestCode == SELECT_SORT_TYPE){
			tagId = data.getStringExtra("tagId");
			itemTypeDesc.setText(data.getStringExtra("name"));
		} else {
			super.onActivityResult(requestCode, resultCode, data);
		}
	}

	@Override
	public void onClick(View v) {
		if(v.getId() == R.id.item_type)
			startActivityForResult(new Intent(mContext, AdjustSortImageTypeActivity.class)
					.putExtra("action", action), SELECT_SORT_TYPE);
		else
			super.onClick(v);
	}

	@Override
	protected void saveChange() {
		JsonObject param = new JsonObject();
		param.addProperty("id", id);
		String title = (String) itemTitleDesc.getText();
		if(!TextUtils.isEmpty(title))
			param.addProperty("title", (String) itemTitleDesc.getText());
		param.addProperty("state", ((boolean)itemOpenDesc.getTag()) ? 1 : 0);
		param.addProperty("tagId", tagId);
		HttpHelper.getInstance(mContext).interfaceUpdateByAdmin(param, UPDATE_BY_ADMIN_CODE, this);
	}
}
